package com.sdjz.domain;

import org.hibernate.Session;
import org.hibernate.cfg.Configuration;

public class Test {


	public static void main(String[] args) {
		
		Student student1 = new Student();
		student1.setName("zhangsan");
		Student student2 = new Student();
		student2.setName("lisi");
		Student student3 = new Student();
		student3.setName("wangwu");
		
		Teacher teacher = new Teacher();
		teacher.setName("wanglaoshi");
		
		teacher.getStudent().add(student1);
		teacher.getStudent().add(student2);
		teacher.getStudent().add(student3);
		
		Configuration cfg = new Configuration();
		Session session =  cfg.configure().buildSessionFactory().openSession();
		session.beginTransaction();
		session.save(teacher);
		session.save(student1);
		session.save(student2);
		session.save(student3);
		
		session.getTransaction().commit();
		session.close();
	}
	
}
